package thread;

import string.TrimDemo;

public class SyncDemo3 {
    public static void main(String[] args) {
//        Runnable r = Foo::doSome;
//        Thread t = new Thread(Foo::doSome);
//        new Thread(Foo::doSome).start();
        Foo f1 = new Foo();
        Foo f2 = new Foo();
        new Thread(()->f1.doSome()).start();
        new Thread(()->f2.doSome()).start();
    }
}
class Foo{
//    public static synchronized void doSome(){
    public static synchronized void doSome(){
        synchronized (Foo.class){
            try {
                Thread t = Thread.currentThread();
                System.out.println(t.getName()+"：正在执行doSome方法...");
                Thread.sleep(5000);
                System.out.println(t.getName()+"：运行doSome方法完毕！");
            } catch (InterruptedException e) {
            }
        }
    }
}